home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / comm / bbs_tee.zip / BBS.C < prev    next >
Text File  |  1987-06-10  |  16KB  |  851 lines

  1.  
  2. #include "stdio.h"
  3. #include "ctype.h"
  4. #include "dos.h"            /* mscv4.0 (others, you're on your own!) */
  5.  
  6. #undef tolower                /* we want function, not macro from ctype.h */
  7.  
  8. #define FAST static
  9.  
  10. static int left_flag, do_padding, num1, num2;
  11. static char outbuf[32], *sp_ptr, pad_character;
  12. static void outs(int (*)(int),char *), outnum(int (*)(int), long, long);
  13. static int getnum(char **);
  14.  
  15. union REGS srv,rrv;        /*
  16.                                 ** this uses the ansiterm.c routines that
  17.                                 ** are provided with Pro-Yam
  18.                                 */
  19. struct {
  20.     char name[26];
  21.     char pass[11];
  22.     int timeson;
  23. } user;
  24.  
  25. struct {
  26.     int users;
  27.     int last_user;
  28.     char spare[35];
  29. } user_hdr;
  30.  
  31. struct {
  32.     char to[26];
  33.     int mnum;
  34. } msg;
  35.  
  36. struct {
  37.     int nxt_mnum;
  38.     int msgs;
  39.     char spare[24];
  40. } msg_hdr;
  41.  
  42. int mail;
  43. int local;
  44. int pers;
  45. int usrs;
  46. int msgs;
  47. int urec;
  48. char uname[26],inpbuf[128];
  49.  
  50. FILE *ufd;
  51. FILE *mfd;
  52.  
  53.  
  54. /* expects:   first last 0 0
  55. **                 |     | |
  56. **   name of user /      | |
  57. **         signed on = 1/  |
  58. **               local = 1/
  59. **
  60. ** above can be achieved through:
  61. **
  62. ** in challeng.t after getting the user's name and confirmation
  63. ** (the name MUST be limited to 25 characters plus a NULL or you will
  64. **  have to change the structs above etc.)
  65. ** add the line: obey "!~bbs %remote 0 0"
  66. **
  67. ** in phones.t add the line: set bbs "~bbs %remote 1 0"
  68. **
  69. ** to run locally enter: bbs <first> <last> 0 1
  70. **                   or: bbs <first> <last> 1 1
  71. ** where <first> is your first name and <last> is your last name
  72. */ 
  73.  
  74. main(argc,argv)int argc;
  75. char **argv;
  76. {
  77.     int i;
  78.  
  79.     if(argc<5) {
  80.         sendf("\nArg error (%d, %s %s %s %s)\n",argc,argv[1],argv[2],argv[3],argv[4]);
  81.         sendf("\nTell my boss!\n");
  82.         exit(1);
  83.     }
  84.     mail=atoi(argv[3]);
  85.     local=atoi(argv[4]);
  86.     strlwr(argv[1]);
  87.     strlwr(argv[2]);
  88.     argv[1][0]=toupper(argv[1][0]);
  89.     argv[2][0]=toupper(argv[2][0]);
  90.     sprintf(uname,"%s %s",argv[1],argv[2]);
  91.     pers=FALSE;
  92.     if(mail)
  93.         goto do_mail;
  94.     sendf("\n\n\n\nRemote Pro-Yam Signon Utility v1.00 (c)1987 Simon J. Ewins\n");
  95.     if((ufd=fopen("\\rem\\users.bbs","r+"))==0) {
  96.         ufd=fopen("\\rem\\users.bbs","w+");
  97.         if(!ufd) {
  98.             sendf("\nCan't make users file, tell my boss!\n");
  99.             exit(1);
  100.         }
  101.         user_hdr.users=0;
  102.         r_put(ufd,0,sizeof(user_hdr),&user_hdr);
  103.     }
  104.     r_get(ufd,0,sizeof(user_hdr),&user_hdr);
  105.     usrs=user_hdr.users;
  106.     sendf("\nSearching %d users.\n",usrs);
  107.     if(usrs==0) {
  108.         i=1;
  109.         goto not_found;
  110.     }
  111.     for(i=1;i<=usrs;++i) {
  112.         sendf("\r# %d ",i);
  113.         r_get(ufd,i,sizeof(user),&user);
  114.         if(!strcmp(user.name,uname))
  115.             goto found;
  116.     }
  117. not_found:
  118.     sendf("\nCan't find %s. Please choose a password: ",uname);
  119.     get_line(10,TRUE,inpbuf);
  120.     if(!strlen(inpbuf))
  121.         goto not_found;
  122.     strcpy(user.name,uname);
  123.     strcpy(user.pass,inpbuf);
  124.     user.timeson=0;
  125.     r_put(ufd,i,sizeof(user),&user);
  126.     ++user_hdr.users;
  127.     user_hdr.last_user=i;
  128.     ++usrs;
  129.     r_put(ufd,0,sizeof(user_hdr),&user_hdr);
  130.     fflush(ufd);
  131.     sendf("\nRemember it and be careful because");
  132. found:
  133.     urec=i;
  134.     sendf("\nUpper and Lower case count!\nPassword: ");
  135.     get_line(10,FALSE,inpbuf);
  136.     if(!strlen(inpbuf) || strcmp(user.pass,inpbuf)) {
  137.         sendf(" <== wrong!");
  138.         goto found;
  139.     }
  140.     ++user.timeson;
  141.     r_put(ufd,urec,sizeof(user),&user);
  142.     fclose(ufd);
  143.     sendf("\nLogin: %d",user.timeson);
  144.     sendf("\nChecking for mail.\n");
  145.  
  146.     if((mfd=fopen("\\rem\\msgs.bbs","r+"))==0) {
  147.         mfd=fopen("\\rem\\msgs.bbs","w+");
  148.         if(!mfd) {
  149.             sendf("\nCan't make msg file, tell my boss!\n");
  150.             exit(1);
  151.         }
  152.         msg_hdr.nxt_mnum=0;
  153.         msg_hdr.msgs=0;
  154.         r_put(mfd,0,sizeof(msg_hdr),&msg_hdr);
  155.     }
  156.     r_get(mfd,0,sizeof(msg_hdr),&msg_hdr);
  157.     if(msg_hdr.msgs==0)
  158.         goto mnot_found;
  159.     for(i=1;i<=msg_hdr.msgs;++i) {
  160.         sendf("\r...\b\b\b");
  161.         r_get(mfd,i,sizeof(msg),&msg);
  162.         if(!strcmp(msg.to,uname))
  163.             goto mfound;
  164.     }
  165. mnot_found:
  166.     sendf("\nCan't find any for you.\n");
  167.     fclose(mfd);
  168.     exit(0);
  169. mfound:
  170.     sendf("\nThere is mail for you...");
  171.     pers=TRUE;
  172.     fclose(mfd);
  173. do_mail:
  174.     if((mfd=fopen("\\rem\\msgs.bbs","r+"))==0) {
  175.         mfd=fopen("\\rem\\msgs.bbs","w+");
  176.         if(!mfd) {
  177.             sendf("\nCan't create the msg file! Tell my boss.");
  178.             exit(1);
  179.         }
  180.         msg_hdr.nxt_mnum=0;
  181.         msg_hdr.msgs=0;
  182.         r_put(mfd,0,sizeof(msg_hdr),&msg_hdr);
  183.     }
  184.     r_get(mfd,0,sizeof(msg_hdr),&msg_hdr);
  185. mloop:
  186.     switch(tolower(menu())) {
  187.     int sho;
  188.     case 'q':
  189.         goto done;    
  190.     case 'a':
  191.         for(i=1,sho=0;i<=msg_hdr.msgs;++i) {
  192.             if(getchr()==24)
  193.                 break;
  194.             sendf("...\b\b\b");
  195.             r_get(mfd,i,sizeof(msg),&msg);
  196.             if(!strcmp(msg.to,"All")) {
  197.                 ++sho;
  198.                 if(shomsg(msg.mnum)=='q')
  199.                     break;
  200.             }
  201.         }
  202.         sendf("\nFound %d public message(s), [Press any key]",sho);
  203.         wtchr();
  204.         break;
  205.     case 'p':
  206.         for(i=1,sho=0;i<=msg_hdr.msgs;++i) {
  207.             if(getchr()==24)
  208.                 break;
  209.             sendf("...\b\b\b");
  210.             r_get(mfd,i,sizeof(msg),&msg);
  211.             if(!strcmp(msg.to,uname) || local) {
  212.                 ++sho;
  213.                 if(shomsg(msg.mnum)=='q')
  214.                     break;
  215.             }
  216.         }
  217.         sendf("\nFound %d message(s) for you, [Press any key]",sho);
  218.         wtchr();
  219.         break;
  220.     case 'u':
  221.         users();
  222.         break;
  223.     case 'e':
  224.         enter();
  225.         break;
  226.     case 's':
  227.         if(local)
  228.             sysop();
  229.         break;
  230.     }
  231.     goto mloop;
  232. done:
  233.     if(pers) {
  234.         sendf("\nDeleting personal messages.\n");
  235.         for(i=1;i<=msg_hdr.msgs;++i) {
  236.             sendf("...\b\b\b");
  237.             r_get(mfd,i,sizeof(msg),&msg);
  238.             if(!strcmp(msg.to,uname)) {
  239.                 msg.to[0]=NULL;
  240.                 r_put(mfd,i,sizeof(msg),&msg);
  241.                 sprintf(inpbuf,"\\rem\\%05d.msg",msg.mnum);
  242.                 unlink(inpbuf);
  243.             }
  244.         }
  245.     }
  246.     fclose(mfd);
  247.     exit(0);
  248. }
  249.  
  250.  
  251. menu()
  252. {
  253.     sendf("\n\n\n\nRemote Pro-Yam Mail Utility v1.00 (c)1987 Simon J. Ewins\n\n");
  254.     sendf("Select: A - Read all public messages\n");
  255.     sendf("        P - Read your personal messages\n");
  256.     sendf("        U - Display users list\n");
  257.     sendf("        E - Enter a message\n");
  258.     sendf("        Q - Quit");
  259.     if(pers)
  260.         sendf(" and delete personal messages");
  261.     putchr('\n');
  262.     sendf("?> ");
  263.     return(wtchr());
  264. }
  265.  
  266.  
  267. shomsg(n)
  268. int n;
  269. {
  270.     FILE *tfd;
  271.     int c,ch;
  272.  
  273.     sendf("\nPress ^X to quit:\n\n");
  274.     sprintf(inpbuf,"\\rem\\%05d.msg",msg.mnum);
  275.     tfd=fopen(inpbuf,"r");
  276.     if(!tfd) {
  277.         sendf("\nHmmm, couldn't open that one!");
  278.         return;
  279.     }
  280.     while((c=fgetc(tfd))!=EOF) {
  281.         if(getchr()==19)
  282.             wtchr();
  283.         if(c==1) {
  284.             sendf("R)ead, S)kip, Q)uit: ");
  285.             ch=tolower(wtchr());
  286.             switch(ch) {
  287.             case 'r':
  288.             case '\r':
  289.                 sendf("\r                     \r");
  290.                 continue;
  291.             case 'q':
  292.             case 's':
  293.                 goto done;
  294.             }
  295.         }
  296.         putchr(c);
  297.         if(getchr()==24)
  298.             break;
  299.     }
  300. done:
  301.     fclose(tfd);
  302.     return(ch);
  303. }
  304.  
  305.  
  306. enter()
  307. {
  308.     char *p,d[9],t[9],*strchr();
  309.     char c,message[2049];
  310.     int pos,hdr,limit;
  311.     FILE *tfd;
  312.  
  313. get_to:
  314.     sendf("\n\nTo: ");
  315.     get_line(25,TRUE,inpbuf);
  316.     if(!strlen(inpbuf))
  317.         return;
  318.     strlwr(inpbuf);
  319.     if(!strcmp(inpbuf,"sysop")) {
  320.         sendf("\nUse 'private' at Yam-Host level to leave comments to Sysop.");
  321.         return;
  322.     }
  323.     if(strcmp(inpbuf,"all")) {
  324.         p=strchr(inpbuf,' ');
  325.         if(!p) {
  326.             sendf("\nNeed first AND last name.");
  327.             goto get_to;
  328.         }
  329.         ++p;
  330.         *p=toupper(*p);
  331.     }
  332.     *inpbuf=toupper(*inpbuf);
  333.     strcpy(msg.to,inpbuf);
  334.     getdte(d,t);
  335.     sprintf(message,"From: %s     Date: %s     Time: %s\n\1\0",uname,d,t);
  336.     pos=0;
  337.     hdr=strlen(message);
  338.     limit=2048-hdr;
  339.     p=message+hdr;
  340.     sendf("\nEnter your message, (%d characters), ^Z to end:\n",limit);
  341.     while(TRUE) {
  342.         c=wtchr();
  343.         if(c==26)
  344.             break;
  345.         if(c=='\b' || c==127) {
  346.             if(pos<1) {
  347.                 putchr(7);
  348.                 continue;
  349.             }
  350.             putchr('\b');
  351.             putchr(' ');
  352.             putchr('\b');
  353.             *p--=NULL;
  354.             --pos;
  355.             continue;
  356.         }
  357.         if(c=='\r') {
  358.             if(pos+2>limit) {
  359.                 putchr(7);
  360.                 continue;
  361.             }
  362.             *p++=c;
  363.             *p++='\n';
  364.             pos+=2;
  365.             putchr('\n');
  366.             continue;
  367.         }
  368.         if(pos+1>limit) {
  369.             putchr(7);
  370.             continue;
  371.         }
  372.         *p++=c;
  373.         ++pos;
  374.         putchr(c);
  375.     }
  376.     *p=EOF;
  377.     r_get(mfd,0,sizeof(msg_hdr),&msg_hdr);
  378.     msg_hdr.msgs++;
  379.     msg.mnum=msg_hdr.nxt_mnum++;
  380.     r_put(mfd,0,sizeof(msg_hdr),&msg_hdr);
  381.     r_put(mfd,msg_hdr.msgs,sizeof(msg),&msg);
  382.     fflush(mfd);
  383.     sprintf(inpbuf,"\\rem\\%05d.msg",msg.mnum);
  384.     tfd=fopen(inpbuf,"w+");
  385.     fwrite(message,pos+hdr+1,1,tfd);
  386.     fclose(tfd);
  387. }
  388.  
  389.  
  390. users()
  391. {
  392.     int